package com.gw.smscheck.util.miaodiyun;


import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

/**
 * 验证码通知短信接口
 * 
 * @ClassName: IndustrySMS
 * @Description: 验证码通知短信接口
 *
 */
public class IndustrySMS
{
	private static String operation = "/industrySMS/sendSMS"; // 短信验证码请求接口

	private static String accountSid = Config.ACCOUNT_SID;
//	private static String to = "18408219086";
//	private static String smsContent = "【高新区数据共享平台】登录验证码：123456，如非本人操作，请忽略此短信。";

	/**
	 * 验证码通知短信
	 */
	public static Map<String,String> execute(String phone)
	{
		if(phone == null || "".equals(phone)){
			return null;
		}
		String tmpSmsContent = null;
		String smsCode = RandomCode.smsCode();
		String smsContent = "【高新区数据共享平台】验证码："+ smsCode +"，验证码有效时间5分钟，如非本人操作，请忽略此短信。";
	    try{
	      tmpSmsContent = URLEncoder.encode(smsContent, "UTF-8");
	    }catch(Exception e){
	      
	    }
	    String url = Config.BASE_URL + operation;
	    String body = "accountSid=" + accountSid + "&to=" + phone + "&smsContent=" + tmpSmsContent
	        + HttpUtil.createCommonParam();

	    // 提交请求
	    String result = HttpUtil.post(url, body);
	    System.out.println("result:" + System.lineSeparator() + result);
		Map<String,String> map = new HashMap<>();
		map.put("phone",phone);
		map.put("smsCode",smsCode);
	    return map;
	}
}
